package com.ldr.custom.spring.v3.webmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Map;

public class GPView {

    private File viewFile;

    private final String DEFAULT_CONTENT_TYPE = "text/html;charset=utf-8";


    public GPView(File file) {
        this.viewFile = file;
    }

    public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws IOException {

        StringBuffer sb=new StringBuffer();


        RandomAccessFile ra=new RandomAccessFile(this.viewFile,"r");

        String line=null;

        while ((line = ra.readLine()) != null) {

        }


        response.setCharacterEncoding("UTF-8");
        response.setContentType(DEFAULT_CONTENT_TYPE);

        response.getWriter().write(sb.toString());

    }
}
